package com.peixunp.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.peixunp.bean.Place;
import com.peixunp.service.OrganizationsService;
import com.peixunp.service.PlaceService;

import finaler.util.Page;
import finaler.util.PageList;

@Controller
@RequestMapping("search")
public class SearchController {

	@Autowired
	private PlaceService placeService;
	
	@Autowired
	private OrganizationsService organizationsService;

	@RequestMapping()
	public String search(HttpServletRequest request) throws Exception {
		Page page = new Page(request);
		page.putParameter("key", request.getParameter("key"));
		page.putParameter("cityId", request.getParameter("cityId") );
		if(request.getParameter("cityId")!=null&&request.getParameter("cityId").equals("")==false){
			Place city  = placeService.findByKey(Integer.parseInt(request.getParameter("cityId")));//城市
			request.setAttribute("city", city);
		}
		PageList schoolList = organizationsService.getOrgList(page );
		request.setAttribute("schoolList", schoolList);
		request.setAttribute("key", request.getParameter("key"));
		return "/school/search";
	}
	

}
